import { requestClient } from '#/api/request';

// 系统公告接口类型定义
export interface SystemAnnouncementItem {
  id: string;
  title: string;
  publisher: string;
  type: string;
  content: string;
  publishTime: string;
  createTime: string;
}

// 系统公告响应接口
export interface SystemAnnouncementResponse {
  status: number;
  message: string;
  data: SystemAnnouncementItem[];
  timestamp: number;
  pageInfo: {
    curPage: number;
    pageSize: number;
    totalRows: number;
    totalPages: number;
    limit: number;
    offset: number;
  };
}

// 系统公告查询参数
export interface SystemAnnouncementParams {
  type?: 'system' | 'upgrade' | 'exam';
  keyWord?: string;
  curPage: number;
  pageSize: number;
}

// 未读消息数量响应接口
export interface UnreadCountResponse {
  status: number;
  message: string;
  data: number;
  timestamp: number;
}

// 获取系统公告列表
export async function getUserMessageApi(params: SystemAnnouncementParams): Promise<SystemAnnouncementResponse> {
  return requestClient.get('/system/get-published-sys-ann-list', { params });
}

// 批量保存用户消息
export async function batchSaveUserMessageApi(data: SystemAnnouncementItem[]) {
  return requestClient.post('/system/batch-save-user-message', data);
}

// 获取用户未读消息数量
export async function getUserMessageUnreadCountApi(): Promise<number> {
  return requestClient.get('/system/get-user-message-unread-count');
}

// 实名认证接口类型定义
export interface RealNameAuthParams {
  nameCn: string;
  idCard: string;
  email: string;
  verificationCode: string;
}

// 实名认证
export async function realNameAuthApi(data: RealNameAuthParams) {
  return requestClient.patch('/system/user-real-name', data);
}

// 通过旧密码修改密码
export async function changePasswordByOldPasswordApi(data: { oldLoginPassword: string; newLoginPassword: string }) {
  return requestClient.patch('/auth/update-user-password', data);
}

// 个人课程相关接口
export interface PersonalCourseParams {
  curPage?: number;
  pageSize?: number;
  name?: string;
  status?: string;
  startTime?: string;
  endTime?: string;
}

// 个人课程项目数据类型
export interface PersonalCourseItem {
  id: string;
  name: string;
  status: string;
  summary: string;
  icon: string;
  createTime: string;
}

// 个人课程响应数据类型
export interface PersonalCourseResponse {
  data: PersonalCourseItem[];
}

// 获取个人课程信息（个人中心）
export async function getCourseInfoForPersonCenterApi(params: PersonalCourseParams): Promise<PersonalCourseResponse> {
  return requestClient.get('/course/get-course-info-for-personCenter', { params });
}
